package model;

import java.util.HashMap;

public class DataMemory extends FunctionalUnit {
	
	private HashMap<Integer, Integer> content = new HashMap<Integer, Integer>();
	
	private int address;
	
	public DataMemory(Pipe sourcePipe, Pipe destinationPipe) {
		super(sourcePipe, destinationPipe);
	}
	
	public void setData (int address, int data) {
		content.put(address,data);
	}
	
	public int getData(int address) {
		return content.get(address);
	}

	public void execute1() {
		address = getPipeData("ADDRESS");
		Facade.getInstance().move(UnitEnum.Pipe3, UnitEnum.DataMemory, address);		
	}
	
	public void execute2() {
		setPipeData("DATA", content.get(address));	
		Facade.getInstance().move(UnitEnum.DataMemory, UnitEnum.Pipe4, address, content.get(address) );
	}

}
